<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>深入理解 Guava EventBus：构建优雅的事件驱动系统</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            min-height: 100vh;
        }
        
        .hero-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        
        .content-card {
            background: rgba(255, 255, 255, 0.95);
            backdrop-filter: blur(10px);
            transition: all 0.3s ease;
        }
        
        .content-card:hover {
            transform: translateY(-2px);
            box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
        }
        
        .code-block {
            background: #1e1e1e;
            color: #d4d4d4;
            border-radius: 8px;
            overflow-x: auto;
            position: relative;
        }
        
        .code-block::before {
            content: 'Java';
            position: absolute;
            top: 0;
            right: 0;
            padding: 4px 12px;
            background: rgba(255, 255, 255, 0.1);
            border-radius: 0 8px 0 8px;
            font-size: 12px;
            color: #888;
        }
        
        .section-title {
            position: relative;
            padding-left: 20px;
        }
        
        .section-title::before {
            content: '';
            position: absolute;
            left: 0;
            top: 50%;
            transform: translateY(-50%);
            width: 4px;
            height: 24px;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            border-radius: 2px;
        }
        
        .highlight-box {
            background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
            color: white;
            padding: 20px;
            border-radius: 12px;
            margin: 20px 0;
        }
        
        .feature-card {
            background: white;
            border-radius: 12px;
            padding: 24px;
            box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
            transition: all 0.3s ease;
        }
        
        .feature-card:hover {
            transform: translateY(-4px);
            box-shadow: 0 8px 30px rgba(0, 0, 0, 0.12);
        }
        
        .mermaid {
            background: white;
            padding: 20px;
            border-radius: 8px;
            margin: 20px 0;
        }
        
        .quote-block {
            border-left: 4px solid #667eea;
            padding-left: 20px;
            margin: 20px 0;
            font-style: italic;
            color: #555;
        }
        
        .drop-cap {
            float: left;
            font-size: 4em;
            line-height: 0.8;
            margin: 0.1em 0.1em 0.1em 0;
            font-weight: 700;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
        }
    </style>
</head>
<body>
    <!-- Hero Section -->
    <div class="hero-gradient text-white py-20">
        <div class="container mx-auto px-6">
            <div class="max-w-4xl mx-auto text-center">
                <h1 class="text-5xl font-bold mb-6 leading-tight">
                    深入理解 Guava EventBus
                </h1>
                <p class="text-2xl mb-8 opacity-90">构建优雅的事件驱动系统</p>
                <div class="flex justify-center space-x-6 text-lg">
                    <div class="flex items-center">
                        <i class="fas fa-broadcast-tower mr-2"></i>
                        <span>发布-订阅模式</span>
                    </div>
                    <div class="flex items-center">
                        <i class="fas fa-sync-alt mr-2"></i>
                        <span>异步事件处理</span>
                    </div>
                    <div class="flex items-center">
                        <i class="fas fa-code mr-2"></i>
                        <span>注解驱动</span>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!-- Main Content -->
    <div class="container mx-auto px-6 py-12">
        <div class="max-w-5xl mx-auto">
            
            <!-- Introduction -->
            <div class="content-card rounded-xl shadow-xl p-8 mb-8">
                <p class="text-lg leading-relaxed text-gray-700">
                    <span class="drop-cap">当</span>我第一次接触Guava的EventBus时，感觉像发现了一块瑰宝。在复杂系统中，传统的观察者模式写起来太繁琐了，而EventBus让我的代码瞬间清爽了很多。让我们一起揭开它的神秘面纱！
                </p>
            </div>

            <!-- Section 1: 发布-订阅模式的实现原理 -->
            <div class="content-card rounded-xl shadow-xl p-8 mb-8">
                <h2 class="section-title text-3xl font-bold mb-6 text-gray-800">
                    <i class="fas fa-network-wired mr-3 text-purple-600"></i>
                    发布-订阅模式的实现原理
                </h2>
                
                <h3 class="text-2xl font-semibold mt-8 mb-4 text-gray-700">为什么需要事件总线？</h3>
                
                <p class="text-gray-700 leading-relaxed mb-6">
                    在大型应用程序中，组件间通信是一个常见挑战。传统方案各有优缺点：
                </p>
                
                <div class="grid grid-cols-1 md:grid-cols-3 gap-4 mb-8">
                    <div class="feature-card">
                        <div class="text-red-500 text-3xl mb-3">
                            <i class="fas fa-link"></i>
                        </div>
                        <h4 class="font-semibold mb-2">直接方法调用</h4>
                        <p class="text-gray-600 text-sm">耦合度高，不灵活</p>
                    </div>
                    <div class="feature-card">
                        <div class="text-orange-500 text-3xl mb-3">
                            <i class="fas fa-eye"></i>
                        </div>
                        <h4 class="font-semibold mb-2">观察者模式</h4>
                        <p class="text-gray-600 text-sm">代码量大，类型安全性差</p>
                    </div>
                    <div class="feature-card">
                        <div class="text-yellow-500 text-3xl mb-3">
                            <i class="fas fa-phone-alt"></i>
                        </div>
                        <h4 class="font-semibold mb-2">回调接口</h4>
                        <p class="text-gray-600 text-sm">容易陷入回调地狱</p>
                    </div>
                </div>
                
                <div class="quote-block">
                    <p>我记得有次维护一个遗留系统，里面的组件通信逻辑就像一盘意大利面条 - 错综复杂，牵一发而动全身。添加新功能简直是噩梦，因为你根本搞不清哪些代码会受到影响。</p>
                </div>
                
                <div class="highlight-box">
                    <h4 class="text-xl font-semibold mb-3">
                        <i class="fas fa-lightbulb mr-2"></i>
                        Guava EventBus 的优势
                    </h4>
                    <ul class="space-y-2">
                        <li><i class="fas fa-check mr-2"></i>事件发布者不需要知道谁在监听</li>
                        <li><i class="fas fa-check mr-2"></i>事件订阅者不需要知道谁发布了事件</li>
                        <li><i class="fas fa-check mr-2"></i>通过注解简化了API使用</li>
                        <li><i class="fas fa-check mr-2"></i>支持继承关系的事件类型</li>
                    </ul>
                </div>
                
                <h3 class="text-2xl font-semibold mt-8 mb-4 text-gray-700">EventBus的核心概念</h3>
                
                <div class="mermaid">
                    graph LR
                        A[事件发布者] -->|post| B[EventBus]
                        B -->|dispatch| C[订阅者1]
                        B -->|dispatch| D[订阅者2]
                        B -->|dispatch| E[订阅者3]
                        
                        style A fill:#f9f,stroke:#333,stroke-width:2px
                        style B fill:#bbf,stroke:#333,stroke-width:2px
                        style C fill:#bfb,stroke:#333,stroke-width:2px
                        style D fill:#bfb,stroke:#333,stroke-width:2px
                        style E fill:#bfb,stroke:#333,stroke-width:2px
                </div>
                
                <p class="text-gray-700 leading-relaxed mb-6">
                    EventBus的核心是<strong>发布-订阅模式</strong>（Publish-Subscribe Pattern），这是观察者模式的一种变体。主要包含三个角色：
                </p>
                
                <div class="grid grid-cols-1 md:grid-cols-3 gap-4 mb-8">
                    <div class="feature-card text-center">
                        <div class="text-purple-600 text-4xl mb-3">
                            <i class="fas fa-envelope"></i>
                        </div>
                        <h4 class="font-semibold mb-2">事件</h4>
                        <p class="text-gray-600 text-sm">包含需要传递的信息</p>
                    </div>
                    <div class="feature-card text-center">
                        <div class="text-blue-600 text-4xl mb-3">
                            <i class="fas fa-bullhorn"></i>
                        </div>
                        <h4 class="font-semibold mb-2">发布者</h4>
                        <p class="text-gray-600 text-sm">发布事件到EventBus</p>
                    </div>
                    <div class="feature-card text-center">
                        <div class="text-green-600 text-4xl mb-3">
                            <i class="fas fa-user-check"></i>
                        </div>
                        <h4 class="font-semibold mb-2">订阅者</h4>
                        <p class="text-gray-600 text-sm">注册到EventBus并处理感兴趣的事件</p>
                    </div>
                </div>
                
                <h4 class="text-xl font-semibold mb-4 text-gray-700">简单示例</h4>
                
                <div class="code-block p-6 mb-6">
                    <pre><code>// 事件类
public class MessageEvent {
    private final String message;
    
    public MessageEvent(String message) {
        this.message = message;
    }
    
    public String getMessage() {
        return message;
    }
}

// 订阅者
public class MessageSubscriber {
    @Subscribe
    public void handleMessage(MessageEvent event) {
        System.out.println("收到消息: " + event.getMessage());
    }
}

// 使用EventBus
EventBus eventBus = new EventBus();
eventBus.register(new MessageSubscriber());
eventBus.post(new MessageEvent("Hello, EventBus!"));</code></pre>
                </div>
                
                <p class="text-gray-700 leading-relaxed">
                    这个简单示例就实现了组件间的解耦通信。事件发布者只负责发布事件，不需要关心谁在处理；而订阅者只需要定义好处理方法并注册到EventBus。
                </p>
            </div>

            <!-- Section 2: 事件分发机制与线程模型分析 -->
            <div class="content-card rounded-xl shadow-xl p-8 mb-8">
                <h2 class="section-title text-3xl font-bold mb-6 text-gray-800">
                    <i class="fas fa-cogs mr-3 text-purple-600"></i>
                    事件分发机制与线程模型分析
                </h2>
                
                <h3 class="text-2xl font-semibold mt-8 mb-4 text-gray-700">线程模型分析</h3>
                
                <div class="grid grid-cols-1 md:grid-cols-2 gap-6 mb-8">
                    <div class="feature-card">
                        <div class="flex items-center mb-4">
                            <div class="text-blue-600 text-3xl mr-3">
                                <i class="fas fa-sync"></i>
                            </div>
                            <h4 class="text-xl font-